//
//  ZFBHomeController.m
//  支付宝
//
//  Created by HaoYoson on 16/6/27.
//  Copyright © 2016年 HaoYoson. All rights reserved.
//

#import "AppDelegate.h"
#import "Masonry.h"
#import "UIColor+Addition.h"
#import "ZFBFunctionListLayout.h"
#import "ZFBHomeController.h"
#import "ZFBHomeFunctionListController.h"
#import "ZFBHomeTopView.h"

@interface ZFBHomeController () <ZFBHomeTopViewDelegate>

@end

@implementation ZFBHomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self setupNavigationBar];
    [self setupUI];
}

- (void)setupUI {
    // 顶部视图
    ZFBHomeTopView *topView = [[ZFBHomeTopView alloc] init];
    topView.delegate = self;
    [self.view addSubview:topView];

    // 首页底部collectionView
    ZFBFunctionListLayout *functionListLayout = [[ZFBFunctionListLayout alloc] init];
    ZFBFunctionListController *functionListController = [[ZFBFunctionListController alloc] initWithCollectionViewLayout:functionListLayout];
    [self addChildViewController:functionListController];
    [self.view addSubview:functionListController.view];

    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.offset(115);
    }];

    [functionListController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom);
        make.left.right.offset(0);
        make.bottom.offset(0);
        //        make.bottom.equalTo(self.mas_bottomLayoutGuideTop);
    }];
}

- (void)setupNavigationBar {
    self.navigationItem.title = @"支付宝";
}

/**
 *   topView中按钮点击的代理方法
 */
- (void)homeTopView:(ZFBHomeTopView *)homeTopView didClickWithButtonType:(HomeTopButtonType)type {
    // 以下代码的push仅为测试效果,工作中不能直接这么写.老老实实新建控制器去.
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor colorWithWhite:.9 alpha:1];
    switch (type) {
        case HomeTopButtonTypeScan:
            vc.navigationItem.title = @"扫一扫";
            break;

        case HomeTopButtonTypePay:
            vc.navigationItem.title = @"付款";
            break;

        case HomeTopButtonTypeXiu:
            vc.navigationItem.title = @"咻一咻";
            break;

        case HomeTopButtonTypeCard:
            vc.navigationItem.title = @"卡卷";
            break;

        default:
            break;
    }

    [self.navigationController pushViewController:vc animated:YES];
}

//- (UIStatusBarStyle)preferredStatusBarStyle {
//    return UIStatusBarStyleLightContent;
//}

@end
